Repository navigation
fix(relinker): reject LOCK-prefixed SIMD lowerings - #10340
Conversation
|
Additional native Windows validation of exact PR head Windows 11 Pro 26H2
This supplements the already-passing Windows CI with exact-head WinLibs testing and negative controls. Only the 21 selected checks are claimed: an initial broader suite was stopped before completion. No title, GPU, performance or full-runtime testing was performed. AI-assisted validation. |
roboterspinne
left a comment
There was a problem hiding this comment.
Reviewed head 1e00b46 merged onto upstream/main aeeaefa (2026-10-24); the merge is clean, also onto the current main 6cd36e6, which extended Amd64OnlyConverterTests.cpp since this branch's base without conflict.
Environment: Windows 11 Home 10.0.26200, Intel i9-12900H, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9, -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.
Results
amd64_only_converterpasses on the merged tree (0.3 s). Red/green per family: with onlySha1Operands.cppreverted the test failsLOCK SHA1RNDS4 was accepted, with onlySha256Operands.cppLOCK SHA256RNDS2 was accepted, with onlySse4aOperands.cppLOCK EXTRQ was accepted; with all three guards it passes. That confirms the body's "each family fails independently", which a single red run cannot show because the harness stops at the first failure.- End to end (
--to-intel --skip-syscall-check --skip-sce-module, code at 0x4000):mainlowersf0 0f 38 cb caasIntel substitution: SHA256RNDS2 at 0x4000 (5 bytes) -> stub 785 bytesand replaces the site withe9 eb 10 00 00, likewisef0 0f 3a cc ca 00(SHA1RNDS4, 6 bytes) andf0 66 0f 78 c0 08 00(EXTRQ, 7 bytes); this branch exits 2 withFAIL: Not a SHA-256 instruction (offset 0x4000),FAIL: Not a SHA-1 instruction (offset 0x4000)andFAIL: SSE4a instruction with a LOCK prefix (offset 0x4000). So the LOCK encodings do reach the decoders throughDecodedInstruction::_skipPrefixesAndRex(which skipsPrefixLock) and the matcher, and the throw fails the conversion through_atFileOffsetwith no catch in between; prefix-order variants (48 f0 ...,f0 48 ...,f0 f0 ...,f0 2e ...) are all refused. - Native probes (child process per sequence): all six fixture encodings raise
STATUS_ILLEGAL_INSTRUCTION(0xc000001d);SHA256RNDS2,SHA256MSG1 [mem],SHA1RNDS4andSHA1MSG1 [mem]without LOCK execute.EXTRQ/INSERTQwithout LOCK also fault here because this Intel CPU has no SSE4a, so the SSE4a half rests on your Ryzen runs and the SDM (LOCK "can be prepended only to" the RMW list; otherwise "an undefined opcode exception will also be generated"). - Failing the conversion matches the project's precedent for mandatory lowerings (
DecodeClzerothrowsCLZERO with a LOCK prefix; MONITORX/MWAITX/RDPRU/MCOMMIT fail via Unsupported); only optional lowerings leave bytes in place. check_conventions.py --base upstream/mainpasses;pr_overlap.pylists only #8042, #8236 and #9184 as not compared (same test file).
Should fix
- MOVNTSS/MOVNTSD, the other two SSE4a lowerings, still accept LOCK.
Amd64OnlyInstructionMatcher::_matchMovnts(lines 200-211) only rejects the register form, andIsMovntss/IsMovntsdgo through the same_skipPrefixesAndRex, so the matcher dispatches to it beforeDecodeSse4aever runs (lines 401-405). With this branch,f0 f3 0f 2b 00 c3yields exit 0,Intel substitution: MOVNTSS at 0x4000 (5 bytes) -> in place 5 bytes, and the site becomesf0 f3 0f 11 00=lock movss DWORD PTR [rax],xmm0, which is #UD (0xc000001d natively; MOVSS is not in the LOCK list); same for MOVNTSD (f0 f2 0f 2b 00->f0 f2 0f 11 00) and for LOCK after REP (f3 f0 0f 2b 00). This is pre-existing onmainand milder than the SHA/EXTRQ case (the output faults like the guest instead of running working code), but it is a reported success for invalid guest bytes, the class this PR closes, and the title and body claim the SSE4a family. Suggest a LOCK scan over the prefix bytes in_matchMovntsthrowingMOVNTSS/MOVNTSD with a LOCK prefix(asClzeroOperands.cpp:29-31does) plus tworequireFailurecases next to the register-form test ({0xF0, 0xF3, 0x0F, 0x2B, 0x07},{0xF2, 0xF0, 0x0F, 0x2B, 0x07}), or name the gap in the body as a follow-up.
Nits
Sha1Operands.cpp:23/Sha256Operands.cpp:23: LOCK shares theNot a SHA-… instructionthrow with 66/F2/F3; the SSE4a and CLZERO decoders name the LOCK prefix. A user converting a title would seeFAIL: Not a SHA-256 instructionfor bytes the matcher already identified as SHA-256.- Body: "the historical native instruction/regression evidence above is retained" refers to nothing above the Tested paragraph; drop it or attach the Linux logs.
- The six checks exercise the decoders directly; a converter-level case like
LOCK RDPRU was accepted(test line ~514) for one LOCK SHA site would pin the end-to-end rejection I ran by hand.
Not checked: AMD hardware (your Ryzen runs cover the SSE4a-without-LOCK side); the full suite on an idle machine; Rosetta-target paths; whether real titles carry such bytes in scanned code.
I found no blocking issue: the three decoders now refuse what the hardware refuses, the counter-check holds per family, and the conversion fails fast where main produced working code for invalid bytes. The one thing I would settle before merge is MOVNTSS/MOVNTSD, in this PR or as a declared follow-up. For disclosure: I have open relinker PRs (#10564, #10402, #10401, #10403, #10390, #10391); none touches codegen/.
Written with AI assistance (Claude Code). I ran the builds, tests, end-to-end conversions and native probes above on my Windows 11 machine.
| continue; | ||
| } | ||
| if (b == PrefixOperandSize || b == PrefixRepne || b == PrefixRep) { | ||
| if (b == PrefixLock || b == PrefixOperandSize || b == PrefixRepne || b == PrefixRep) { |
There was a problem hiding this comment.
Nit: for f0 the matcher has already identified a SHA-256 opcode, so FAIL: Not a SHA-256 instruction (offset 0x4000) hides the cause; the SSE4a and CLZERO decoders say "... with a LOCK prefix". A separate if (b == PrefixLock) throw CodegenException("SHA-256 instruction with a LOCK prefix"); (and the SHA-1 twin) would match them.
There was a problem hiding this comment.
Addressed in cfa8c10: both SHA decoders now report SHA-1 instruction with a LOCK prefix / SHA-256 instruction with a LOCK prefix, matching the explicit SSE4a/CLZERO diagnostics. Linux Release relinker-only build and all 240 checks pass. AI-assisted.
| pos += 1; | ||
| continue; | ||
| } | ||
| if (b == PrefixLock) { |
There was a problem hiding this comment.
This never runs for the other two SSE4a lowerings: MOVNTSS/MOVNTSD are dispatched to _matchMovnts (Amd64OnlyInstructionMatcher.cpp:401-405) before DecodeSse4a, and that path only rejects the register form, so f0 f3 0f 2b 00 still converts with Intel substitution: MOVNTSS ... in place and the site becomes f0 f3 0f 11 00 (lock movss, #UD, 0xc000001d natively); same for MOVNTSD and for f3 f0 .... Pre-existing on main, but the title claims the SSE4a family. A LOCK scan in _matchMovnts throwing MOVNTSS/MOVNTSD with a LOCK prefix (as ClzeroOperands.cpp:29-31) plus two requireFailure cases would close it; otherwise please name it as a follow-up.
There was a problem hiding this comment.
Kept the decoder fixes scoped here as agreed with @oneandonlydean. The description now explicitly excludes MOVNTSS/MOVNTSD and names independent follow-up #10713. That PR rejects LOCK in the in-place matcher, covers both prefix orders for both MOVNT forms at converter level, and checks the failure offset. The new regression fails on unchanged main and passes with the guard; native AMD probes fault for all four LOCK encodings while all four unlocked controls execute. AI-assisted.
| } | ||
|
|
||
| void sse4aOperands() { | ||
| requireFailure([] { const Bytes bytes = {0xF0, 0x66, 0x0F, 0x78, 0xC0, 0x08, 0x00}; (void)Codegen::DecodeSse4a(bytes.data(), bytes.size()); }, "LOCK EXTRQ was accepted"); |
There was a problem hiding this comment.
Nit, optional: these exercise the decoders directly; one converter-level case in the style of LOCK RDPRU was accepted (line ~514) for a LOCK SHA site would also pin that the conversion fails rather than lowering, which I checked by hand (FAIL: Not a SHA-256 instruction (offset 0x4000) on this branch, Intel substitution: SHA256RNDS2 ... -> stub 785 bytes on main).
There was a problem hiding this comment.
Added converter-level rejection cases for both SHA-256 and SHA-1 in cfa8c10. They prepend LOCK to the existing valid segment fixtures and require conversion to throw with file offset 0x200; the unchanged valid fixtures still lower successfully. All 240 Linux relinker-only checks pass. AI-assisted.
|
@Filip722 @roboterspinne I checked the dispatch order and agree that LOCK MOVNTSS/MOVNTSD bypass DecodeSse4a: _matchMovnts preserves F0 while replacing 0F 2B with 0F 11. The resulting lock movss/movsd is still invalid. I’m comfortable keeping the three decoder fixes scoped here and handling MOVNTSS/MOVNTSD in a declared follow-up: this is a pre-existing rejection/diagnostic gap, and the output still faults rather than becoming working code for invalid guest bytes. Please make that scope explicit in the description and name the follow-up before landing, so this is not presented as complete SSE4a LOCK rejection. A prefix-order regression for each MOVNT form and a converter-level SHA case would make good coverage for that work. |
|
@roboterspinne @oneandonlydean addressed the review in The separate MOVNTSS/MOVNTSD follow-up is #10713. It rejects LOCK in the in-place matcher and covers LOCK before/after the mandatory prefix for each form. The description here now limits this PR to SHA-1, SHA-256, EXTRQ and INSERTQ; neither PR depends on the other. Local validation: the complete Linux Release relinker-only suites pass (240 checks here; 248 for #10713). The MOVNT regression fails on unchanged main, and all four native AMD LOCK probes raise SIGILL while unlocked controls execute. Convention and whitespace checks pass. Hosted checks for the new commits are still running. AI-assisted implementation and validation. |
|
@Filip722 Thanks, checked cfa8c10 merged onto
All three of my comments are addressed from my side. Hosted CI on cfa8c10 was green on ubuntu, windows and ASan when I looked; the macOS jobs were still running. Written with AI assistance (Claude Code). I ran the build and tests above on my Windows 11 machine. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head cfa8c10d2184210f0eaf6aa79e9441f72c1f28a4. The SHA-1/SHA-256 decoders and SSE4a decoder now reject LOCK explicitly, and the tests cover register and memory encodings plus converter-level failure offsets for both SHA families. The stated scope excludes LOCK-prefixed MOVNTSS/MOVNTSD, which is tracked separately in #10713.
I configured a Release relinker-only build, compiled amd64_only_converter_tests, and ran ctest -R '^amd64_only_converter$' (1/1 passed). tools/check_conventions.py --base upstream/main --head upstream/pr-10340 and git diff --check also pass. Hosted eligibility/conventions/labels, Ubuntu/Windows/macOS relinker and ASan checks are green; product jobs are skipped by policy. The author additionally reports all 240 Linux relinker-only checks passing. I found no blocker.
What
LOCK-prefixed SHA-1/SHA-256 and SSE4a EXTRQ/INSERTQ instructions could be decoded and lowered after discarding LOCK, turning invalid guest bytes into executable code. Reject these encodings before generating replacements.
MOVNTSS/MOVNTSD use a separate in-place matcher and are outside this PR's decoder fixes. Their pre-existing rejection/diagnostic gap is addressed independently in #10713; this PR does not claim complete SSE4a LOCK rejection. Neither PR depends on the other.
Tested
Linux x86-64: the regressions fail on unchanged main and each family fails independently when its guard is removed. The complete relinker suite passes. All six invalid byte sequences raise SIGILL on AMD Ryzen 5 7640HS. Windows and macOS execution not tested.
Original patch based on main
a19e7f6fdc54. Manual review of conflicting #7918, #8042, #8236 and #9184 found only disjoint test changes.Review update
cfa8c10d2184: Linux x86-64, GCC 15.2.0, Release relinker-only build and the complete suite pass, including the new SHA-1 and SHA-256 converter rejection/file-offset checks. The native Linux probes described above and the native Windows validation cover the original head1e00b460b9f2; native instruction probes and Windows/macOS execution were not rerun for this review update.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)